<template>
  <div>
    <Card title="提问">
      <Form label-position="top" :model="form">
        <FormItem prop="caption" label="标题">
          <Input type="text" v-model="form.caption" placeholder="请输入标题" />
        </FormItem>
        <FormItem prop="category_id" label="类别">
          <Select v-model="form.category_id" placeholder="请选择类别">
            <Option v-for="(item,index) in categoryList" :key="index" :value="item.id">{{item.name}}</Option>
          </Select>
        </FormItem>
        <FormItem prop="content" label="内容">
          <Input type="textarea" v-model="form.content" placeholder="请输入内容" />
        </FormItem>
        <Button type="primary" @click="submit">提交</Button>
      </Form>
    </Card>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "Ask",
  data() {
    return {
      form: {
        caption: ""
      },
      categoryList:[]
    };
  },
  methods:{
       getCategoryList(){
          axios.get("/api/category/list").then(res=>{
                var data=res.data
                if (data.code==0){
                   this.categoryList=[...data.data]
                }
          })
       },
       async submit(){
          await axios.post("/api/ask/submit",this.form).then(res=>{

          }).catch(res=>{

          })
       }
  },
  created(){
        console.log("create")
        this.getCategoryList()
  },
};
</script>

<style lang="scss" scoped>
</style>
